package com.xl.basic.config;

import cn.hutool.system.SystemUtil;
import com.xl.basic.entity.Properties;
import com.xl.basic.utils.PropUtils;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * springboot web方面的配置
 *
 * @author 钟勇
 * Create in 2023/8/17 15:48
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
    /**
     * 访问地址映射
     *
     * @param registry registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        Properties.File fileProp = PropUtils.getProp().getFile();
        //上传的文件目录映射
        String uploadDir = SystemUtil.getOsInfo().isWindows() ? fileProp.getWindowPath() : fileProp.getLinuxPath();
        registry.addResourceHandler(fileProp.getVisitPath() + "/**").addResourceLocations("file:" + uploadDir + "/");
    }


}
